﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Kokomo.Mirror.CliMetadata.Signatures
{
	class FunctionPointerTypeSpec : TypeSpec
	{
		public MethodRefSignature methodRefSig;

		public override bool IsComplete
		{
			get { return (this.methodRefSig != null); }
		}

		public override Type ResolveType(
			Module module,
			bool throwOnError,
			Type[] genericTypeArgs,
			Type[] genericMethodArgs
			)
		{
			if (!this.IsComplete) throw new InvalidOperationException();

			CliModule mirrorModule = module as CliModule;
			if (mirrorModule != null)
				return mirrorModule.CliAssembly.LoadContext.IntPtrType;
			else
				return typeof(IntPtr);
		}

		public override string ToString()
		{
			return "Function pointer: " + this.methodRefSig.ToString();
		}

		public override bool Equals(object obj)
		{
			FunctionPointerTypeSpec other = obj as FunctionPointerTypeSpec;
			if (other == null) return false;

			return this.methodRefSig.Equals(other.methodRefSig);
		}

		public override bool Matches(
			Type type,
			Module module,
			Type[] genericTypeArguments,
			Type[] genericMethodArguments
			)
		{
			return false;
		}
		public override bool Matches(
			Module ownerModule,
			TypeSpec other,
			Module otherModule
			)
		{
			return false;
		}
	}
}
